<%-- 
  - Author: Ismail Basha
  - Date: 4-Jan-'2012
  - Copyright Notice: TRAKHEES
  - Description: edit.jsp
 --%>
<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>


<script type="text/javascript">
	function deleteService(obj) {
		var inputHidden = obj.parents("tr").find("input:hidden");
		inputHidden.val("");
		inputHidden.appendTo("#hiddenInputs");
		obj.parents("tr").remove();
		if ($("#serviceListTable>tbody>tr").length == 0) {
			$("#serviceListTable").hide();
		}
	}
	function addSelectedItems() {
		var bAdded = false;
		$("#divSearchResult")
				.find("input:checked")
				.each(
						function() {
							bAdded = true;
							var id = $(this).val();
							var hidden_td = '<input type="hidden" name="arrServices" value="' + id + '" />';
							var en_name_td = '<td>'+ hidden_td + $($(this).parents("tr").children().get(0)).html()+'</td>';
							var ar_name_td = '<td>'+$($(this).parents("tr").children().get(1)).html()+'</td>';
							var delete_td = '<td><input type="button" value="<spring:message code="label.button.delete" />"  onclick=\'javascript:deleteService($(this));\' style="width: 75px" class="submit"> </input></td>';
							var bElmtExist = false;
							$("input:hidden").each(function() {
								if ($(this).val() == id) {
									bElmtExist = true;
									return;
								}
							});
							if (!bElmtExist) {
								$("#serviceListTable>tbody").append(
										'<tr>' + en_name_td
												+ ar_name_td + delete_td
												+ '</tr>');
								//$("input:submit, input:reset, input:button, input:file").button();
							}
						});
		$(this).dialog("close");
		if (bAdded)
			$("#serviceListTable").show();
	}
	$()
			.ready(
					function() {

						$("#btnAddSearch")
								.click(
										function() {
											$("#popupDialog")
													.dialog(
															{
																autoOpen : true,
																width : 800,
																height : 400,
																maxHeight : 800,
																buttons : {
																	'<spring:message code="label.button.continue" />' : {
																		'text': '<spring:message code="label.button.continue" />',
																		'class': 'select',
																		'click': addSelectedItems
																		},

																	'<spring:message code="label.button.close" />' : {
																		'text': '<spring:message code="label.button.close" />',
																		'class': 'close',																		
																		'click' : function() {
																		$(this)
																				.dialog(
																						"close");
																		}
																	}
																},
																modal : true,
																title : '<spring:message code="label.search.service" />'

															});
											return false;
										});
						$("#btnServSearch")
								.click(
										function() {
											var searchKey = $("#strSearchKey")
													.val();
											if (searchKey == "") {
												jAlert(
														'error',
														'<li><spring:message code="label.search.key.empty" /></li>',
														'<spring:message code="label.errormessage" />');
												return false;
											} else {
												$
														.ajax({
															type : "POST",
															url : "user/general/manage/service/searchService?searchKey="
																	+ searchKey,
															cache : false,
															contentType : "application/html",
															dataType : "html",
															success : function(
																	result) {
																$(
																		"#divSearchResult")
																		.html(
																				result);
																$(
																		"#divSearchResult")
																		.show();
															}
														});
											}
										});
						//$("input:submit, input:reset, input:button, input:file").button();

						$("#PersonRegister")
								.validate(
										{
											onfocusout : false,
											onkeyup : false,
											rules : {

												strClientPersonNameENG : "required",
												strClientPersonNameARB : "required",
												strMobileNo : "required",
												strUserName : "required",
												iSecQuestion : "required",
												strSecretAnswer : "required",
												strEmailAddress : "required",
												strStatus : "required"
											},
											showErrors : function(errorMap,
													errorList) {

												var errors = '<ul>';
												var label;
												if (errorList.length) {
													$.each(errorMap, function(
															name, value) {
														label = $(
																"label[for='"
																		+ name
																		+ "']")
																.html();
														label = value + '['
																+ label + ']';
														errors = errors
																+ '<li>'
																+ label
																+ '</li>';

													});
													errors = errors + '</ul>';
													jAlert('error', errors,
															'<spring:message code="label.errormessage" />');
												}
											}

										});

					});
</script>

<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>' class="t_fin-black">

	<form:form name="PersonRegister" id="PersonRegister" method="POST"
		enctype="multipart/form-data"
		modelAttribute="<%=ConstantsAdmin.USER_PERSON_INFO_MODEL_KEY %>">


		<spring:hasBindErrors
			name="<%=ConstantsAdmin.USER_PERSON_INFO_MODEL_KEY %>">
			<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'error',
											'<li><form:errors path="*" delimiter="<li>"/>',
											'<spring:message code="label.errormessage" />');
								});
			</script>
		</spring:hasBindErrors>
			<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix">
				<spring:message code="label.menu.edit.employee" />
			</div>
				<fieldset>
					<legend>
						<spring:message code="label.login.details" />
					</legend>
				</fieldset>				
		<div class="ui-widget_c ui-corner-all">
			<div class="ui-widget_content_c t_form-left">
					<div class="fm-req">
						<form:label path="strPersonNameENG">
						<span class="t_star">*</span>
							<spring:message code="label.empname.eng" />
						</form:label>
						<form:input path="strPersonNameENG" id="strClientPersonNameENG"
							size="20" maxlength="100" />
					</div>
					<div class="fm-req">
						<form:label path="strPersonNameARB">
						<span class="t_star">*</span>
							<spring:message code="label.empname.arab" />
						</form:label>
						<form:input path="strPersonNameARB" id="strClientPersonNameARB"
							size="20" maxlength="100" />
					</div>
					<div class="fm-req">
						<form:label path="strUserName">
							<spring:message code="label.client.person.register.user.name" />
						</form:label>
						<form:input path="strUserName" id="strUserName" size="20"
							maxlength="100" readonly="true" />
					</div>
					<div class="fm-req">
						<form:label path="iSecQuestion">
						<span class="t_star">*</span>
							<spring:message code="label.secretquestion" />
						</form:label>
						<c:choose>
							<c:when
								test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
								<form:select path="iSecQuestion" items="${userSecretQuestion}"
									id="iSecQuestion" itemLabel="labelAr" itemValue="id"
									class="fm-opt"/>
							</c:when>
							<c:otherwise>
								<form:select path="iSecQuestion" items="${userSecretQuestion}"
									id="iSecQuestion" itemLabel="labelEn" itemValue="id"
									class="fm-opt"/>
							</c:otherwise>
						</c:choose>

					</div>
					<div class="fm-req">
						<form:label path="strSecretAnswer">
						<span class="t_star">*</span>
							<spring:message code="label.client.person.register.secretAnswer" />
						</form:label>
						<form:input path="strSecretAnswer" id="strSecretAnswer" size="20"
							maxlength="100" />
					</div>

					<div class="fm-req">
						<form:label path="strEmailAddress">
						<span class="t_star">*</span>
							<spring:message code="label.client.person.register.emailAddress" />
						</form:label>
						<form:input path="strEmailAddress" id="strEmailAddress" size="20"
							maxlength="100" />
					</div>

					<div class="fm-req">
						<form:label path="strMobileNo">
						<span class="t_star">*</span>
							<spring:message code="label.client.person.register.mobNo" />
						</form:label>
						<form:input path="strMobileNo" id="strMobileNo" size="20"
							maxlength="100" />
					</div>
					<div style="display:none;">
						<form:label path="strMobileNotification">
							<spring:message code="label.client.person.register.notifications" />
						</form:label>
						<div class="fm-multi">
							
							<spring:message code="label.emailnotification" />
							<form:checkbox path="strEmailNotification" value="Y"
								id="strEmailNotification" cssClass="opt-input"/>
							<spring:message code="label.smsnotification" />
							<form:checkbox path="strMobileNotification" value="Y"
								id="strMobileNotification" cssClass="opt-input"/>
						</div>
					</div>
					<!--<div style="clear:both"><br></div>
					--><div class="fm-req t_form" style="border:0;">
						<form:label path="strStatus">
						<span class="t_star">*</span>
							<spring:message code="label.accountstatus" />
						</form:label>
						<span style="width: 50px; font-weight: normal;" class="t_fin-black"> <c:forEach
								items="${userAdminLockUser}" var="status">
								<c:out value="${status.displayLabel}"></c:out>
								<form:radiobutton path="strStatus" id="strStatus"
									value="${status.id}" cssClass="opt-input"></form:radiobutton>
							</c:forEach> </span>
					</div>
			</div>
				<fieldset>
					<legend>
						<spring:message code="label.service" />
					</legend>
				</fieldset>
			<div class="ui-widget_content_c t_form-left">				
					<div class="fm-req">
						<spring:message code="label.service" />
						<input type="button" name="open" id="btnAddSearch"
							class="search"
							value="<spring:message code="label.search.add"/>" class="t_btns"/>

					</div>
					<div id="tableServiceListWrapper">
						<table id="serviceListTable" width="100%" class="t_grid-table">
						<caption><spring:message code="label.service.selected" /></caption>
							<thead>
								<tr class="ui-jqgrid-labels">
									<th width="200px" class="ui-state-default ui-th-column ui-th-ltr"><spring:message
											code="label.service.name.en" /></th>
									<th width="200px" class="ui-state-default ui-th-column ui-th-ltr"><spring:message
											code="label.service.name.ar" /></th>
									<th width="100px" class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.select" />
									</th>
								</tr>
							</thead>
							<tbody>
								<c:if test="${not empty userAdminEditServiceList}">

									<c:forEach items="${userAdminEditServiceList}" var="service"
										varStatus="loop">
										<tr>
											<td><form:hidden path="arrServices"
													label="${service.strServiceNameArb}"
													value="${service.strServiceID}" />
													<c:out value="${service.strServiceNameEng}"></c:out>
											</td>
											<td><c:out value="${service.strServiceNameArb}"></c:out>
											</td>
											<td><input type="button"
												value="<spring:message code="label.button.delete" />"
												onclick='javascript:deleteService($(this));'
												style="width: 75px" class="submit"> </input></td>
										</tr>

									</c:forEach>
								</c:if>
							</tbody>
						</table>
					</div>
					<c:if test="${empty userAdminEditServiceList}">
						<script>
							$("#serviceListTable").hide();
						</script>
					</c:if>
					<span id="hiddenInputs"></span>
				</fieldset>


				<div id="fm-submit" class="fm-req">
					<input
						type="submit" name="submit"
						value="<spring:message code="label.button.save" />"  class="t_btns save"/>
				
					<input type="reset" name="reset"
						value="<spring:message code="label.button.reset" />" class="t_btns reset"/> 

				</div>


			</div>
		</div>
		<div id="popupDialog" style="display: none;" dir='<spring:message code="page.dir"/>'  align='<spring:message code="page.align"/>' class="t_form-left t_fin-black">
			<div>
				<form:label path="strSearchKey">
					<spring:message code="label.search.service.name" />
				</form:label>
				<form:input path="strSearchKey" id="strSearchKey"/>
				<input type="button" name="search" id="btnServSearch"
					class="search"
					value="<spring:message code="label.button.search"/>"/>

			</div>
			<div id="divSearchResult" ></div>
		</div>
	</form:form>
</div>